<?php
/**
 * 	Bushido
 *
 * @category   Bushido
 * @package    Bushido_Model_ETL
 * @copyright  Copyright (c) 2009 Nathan Keyes
 * @author Nathan Keyes
 * @version    $Id: Generator.php 7 2009-11-14 22:42:08Z nkeyes $
 */

/**
 * 
 * @category   Bushido
 * @package    Bushido_ETL
 * @copyright  Copyright (c) 2009 Nathan Keyes
 */

class Bushido_Db_Table_Generator
{
	
	const TEMPLATE_CLASS = 'Bushido_Db_Table_Template';
	const DEFAULT_CLASS_PREFIX = 'Bushido_Db_Table_';
	
	protected $_tableName;
	
	
	public function generateClassFile()
	{	
		$file = Zend_CodeGenerator_Php_File::fromReflectedFileName
		(
			dirname(__FILE__) . '/Template.php'
		);
		
		$class = current($file->getClasses());
		/*
		$class->setProperties
		(
			array
			(
				array
				(
					'name' => '_name',
					'defaultValue' => $this->_tableName,
					'visibility' => 'protected',
				),
				array
				(
					'name' => '_sequence',
					'defaultValue' => true,
					'visibility' => 'protected',
				),
				array
				(
					'name' => '_referenceMap',
					'defaultValue' => array(),
					'visibility' => 'protected',
				),
				array
				(
					'name' => '_childMap',
					'defaultValue' => array(),
					'visibility' => 'protected',
				),
			)
		);
		*/
		$class->setName(self::DEFAULT_CLASS_PREFIX .ucfirst($this->_tableName));
		$class->setIndentation("\t");
		
		$file->setClass($class);
		echo $file->generate();
	}
	

	/**
	 * Initilizes the object
	 * 
	 * @return void
	 */
	public function init()
	{
		//get commandline options
		try
		{
			$this->obj_options = new Zend_Console_Getopt(NULL);
			$this->obj_options->parse();
		}
		catch (Zend_Console_Getopt_Exception $e)
		{
			echo $e->getUsageMessage();
			exit;
		}
		
		$this->_tableName = array_shift($this->obj_options->getRemainingArgs());
		
	}
	
	/**
	 * Main function to be called statically
	 * 
	 * @return void
	 */
	public static function main()
	{
		$className = __CLASS__;
		
		$instance = new $className();
		try
		{
			$instance->init();
			$instance->generateClassFile();
		}
		catch (Exception $e)
		{
			echo $e->getMessage();
			exit;
		}
	}
}